<?php
// Module Body

function monitor_clear_datafiles() {
	global $cfg;
	$filename[] = $cfg['basedir']."/server/data/sysmon.dat";
	$filename[] = $cfg['basedir']."/server/data/ram.dat";
	$filename[] = $cfg['basedir']."/server/data/swap.dat";
	$filename[] = $cfg['basedir']."/server/data/uptime.dat";
	foreach($filename as $file) {
		if (is_file($file)) {
			unlink($file);
		}
	}
}

function monitor_check(&$data) {
	global $cfg;

	///////////////////////
	// CONFIGURATION :  filename containing the scan data
	$filepath = $cfg['basedir'].'/server/data/';
	unset($monitor);

	// get service monitoring information
	$monitor = array();

	call_hook('server:service:monitor', $monitor);
	// Prepare $data
	$data = serialize($monitor);
	// write down results
	file_put_contents($filepath.'sysmon.dat',$data);

	// get stat (server-side)
	// get RAM information
	$ram_total = trim(`free -m |grep -i mem | cut -c15-18`);
	$ram_used = trim(`free -m |grep -i mem | cut -c26-29`);
	// write down results
	file_put_contents($filepath."ram.dat",$ram_used." / ".$ram_total);

	// get SWAP information
	$swap_total = trim(`free -m |grep -i swap | cut -c15-18`);
	$swap_used = trim(`free -m |grep -i swap | cut -c26-29`);
	// write down results
	file_put_contents($filepath."swap.dat",$swap_used." / ".$swap_total);

	// get server uptime
	$serverinfo = trim(`uptime | cut -c11-`);
	// write down results
	file_put_contents($filepath."uptime.dat",$serverinfo);
}

function monitor_add_menu(&$data) {
	global $menu;

	$menu['personal'][] = 'serverstatus';
	$menu['domain'][] = 'serverstatus';
	$menu['reseller'][] = 'serverstatus';
	$menu['server'][] = 'serverstatus';
	$menu['server'][] = 'serverinfo';
}

function monitor_add_lang(&$data) {
	global $T;
	switch($data['lang']) {
		default:
			/*$T['personal']['serverstatus'] = 'Server Status';
			$T['domain']['serverstatus'] = 'Server Status';
			$T['reseller']['serverstatus'] = 'Server Status';
			$T['server']['serverstatus'] = 'Server Status';
			$T['server']['serverinfo'] = 'Server Information';
			*/
			$T['menu']['serverstatus'] = 'Server Status';
			$T['menu']['serverinfo'] = 'Server Information';
			break;
	}
}

function monitor_user(&$data) {
	global $T;
	$cp = $data['_cp'];
	$url = $data['_url'];
	// Get system data
$monit = get_stat('monitor');
$ram = get_stat('ram');
$swap = get_stat('swap');
$cpu = get_stat('cpu');
$uptime = get_stat('uptime');
?>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0" class="tblbg">
	<tr>
		<td>
		<table border="0" cellspacing="1">
			<tr>
				<td colspan="2" class="tbltop">&nbsp;<?=$T['menu'][$url];?>&nbsp;</td>
			</tr>
			<tr>
	          <td width="100%" colspan="2">
                    <table border="0" cellpadding="3" width="100%" class="content">
                      <tr>
                        <td valign="top" width="10%" nowrap>
							<b><?=$T['Uptime'];?>:&nbsp;<br/>
                          	<?=$T['Processor Usage'];?>:&nbsp;
                          	</b>
						</td>
                        <td valign="top" width="100%" nowrap><?=$cpu['uptime'];?><br />
                          <?=$cpu['cpu'];?>
                        </td>
                      </tr>
                      <tr><Td></td></tr>
                    </table>
                    <table border="0" width="100%" class="content">
                      <tr>
                        <td align="left" bgcolor="#EBEBEB" nowrap><font size="1"><b><?=$T['Service Name'];?></b></font></td>
                        <td align="left" bgcolor="#EBEBEB" nowrap><font size="1"><b><?=$T['Status'];?></b></font></td>
                      </tr>
			<?
			if (is_array($monit)) {
				foreach($monit as $key => $val) {
					if ($T[$key.' service'] != "") {
						?>
						<tr>
						<td nowrap class="features">
						&nbsp;&nbsp;<?=$T[$key.' service'];?>
						</td>
						<td nowrap class="features">
						<span class="service<?php
						if ($T[$val] == $T['up']) {
							echo 'ok">&nbsp;<img src="icon/up.gif" border="0" width="16" height="16" alt="'.$T['up'].'"/>&nbsp;'.$T['up'];
						} else {
							echo 'notok">&nbsp;<img src="icon/down.gif" border="0" width="16" height="16" alt="'.$T['down'].'"/>&nbsp;'.$T['down'];
						}
						?>&nbsp;</span>
						</td>
						</tr>
				<? 	}
				}
			}?>
			<tr><Td><br /></td></tr>
                    </table>

                    <table border="0" width="100%" class="content">
			<tr>
                        <td align="left" bgcolor="#EBEBEB" nowrap><font size="1"><b><?=$T['Memory Usage'];?></b></font></td>
                        <td align="left" bgcolor="#EBEBEB" nowrap><font size="1"><b><?=$T['Used'];?>&nbsp;</b></font></td>
                        <td align="left" bgcolor="#EBEBEB" nowrap><font size="1"><b><?=$T['Total'];?>&nbsp;</b></font></td>
                        <td align="left" bgcolor="#EBEBEB" nowrap colspan=2><font size="1"><b><?=$T['Used'];?> %&nbsp;</b></font></td>
			</tr>
			<tr>
                        <td nowrap class="features">
                          &nbsp;&nbsp;<?=$T['RAM'];?>
                        </td>
                        <td nowrap class="features">
                          &nbsp;&nbsp;<?=$ram['used'];?> <?=$T['mb'];?>
                        </td>
                        <td nowrap class="features">
                          &nbsp;&nbsp;<?=$ram['total'];?> <?=$T['mb'];?>
                        </td>
                        <td nowrap class="features">
                          <span class="service<?php $tmp=(round(($ram['total'] != 0) ? round($ram['used'] / $ram['total'] * 100) : 0,2));
                          if ($tmp<100) echo 'ok">'; else echo 'notok">';
                          echo "&nbsp;".$tmp; ?>&nbsp;</span>%
                        </td>
                        <td class="features"><div class="bargraphContainer"><div class='bargraph' style="width: <?=round(($ram['total'] != 0) ? round($ram['used'] / $ram['total'] * 100) : 0);?>%;"></div></div></td>
			</tr>
			<tr>
                        <td nowrap class="features">
                          &nbsp;&nbsp;<?=$T['SWAP'];?>
                        </td>
                        <td nowrap class="features">
                          &nbsp;&nbsp;<?=$swap['used'];?> <?=$T['mb'];?>
                        </td>
                        <td nowrap class="features">
                          &nbsp;&nbsp;<?=$swap['total'];?> <?=$T['mb'];?>
                        </td>
                        <td nowrap class="features">
                          <span class="service<?php $tmp=(round(($swap['total'] != 0) ? round($swap['used'] / $swap['total'] * 100) : 0,2));
                          if ($tmp<100) echo 'ok">'; else echo 'notok">';
                          echo "&nbsp;".$tmp; ?>&nbsp;</span>%
                        </td>
                        <td class="features"><div class="bargraphContainer"><div class='bargraph' style="width: <?=round(($swap['total'] != 0) ? round($swap['used'] / $swap['total'] * 100) : 0);?>%;"></div></div></td>
                      </tr>
                    </table>
                  </td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</div>
	<?
}

function monitor_server(&$data) {
	global $T, $cfg, $current_url;
	$cp = $data['_cp'];
	$url = $data['_url'];
	$current_url = $data['_current_url'];
	$action = $data['_action'];
	$confirm = $data['_confirm'];
	$userdata = $data['_userdata'];
	$personaldata = $data['_personaldata'];
	$domaindata = $data['_domaindata'];
	$resellerdata = $data['_resellerdata'];
	// Get system data
	$monit = get_stat('monitor');
	$ram = get_stat('ram');
	$swap = get_stat('swap');
	$cpu = get_stat('cpu');
	$uptime = get_stat('uptime');
	?>
	<div align="center">
	<?
	if ($action AND $confirm == "true" AND $userdata['type'] != 'demo') {

		// Initialize
		unset($error);
		$error = service($action,$data['service']);
		if ($error)
			echo "<br>&nbsp;&nbsp;&bull; ".implode("<br>\n&nbsp;&nbsp;&bull; ",$error)."<br>\n";
		else {
			// Save old state
			$state = $T[$monit[$data['service']]];
			$service_complete = false;
			// wait monitor refresh before to print the page
			if (($action == "restart") AND ($state == $T['down']))
				$refresh = 1;
			elseif ($action != "restart")
				$refresh = 1;
			else {
				$refresh = 0;
				$service_complete = true;
			}

			if ( $refresh ) {
				$monit = get_stat('monitor');
				$i = 0;
				while(($T[$monit[$data['service']]] == $state) && ($i < $cfg['init']['timeout'])) {
					$i += 1;
					sleep(1);
					$monit = get_stat('monitor');
				}
				if ($T[$monit[$data['service']]] != $state) {
					$service_complete = true;
				}
			}

			if ($service_complete) {
				// print action result
				echo $T['service '.$action]."<b>".$data['service']."</b><br><br>\n";
			} else {
				// print action waiting
				echo $T['service waiting '.$action]."<b>".$data['service']."</b><br><br>\n";
			}
		}
	} elseif ($action AND $confirm == "true" AND $userdata['type'] == 'demo') {
		echo "<center>".$T['err']['demo user']."</center>";
	}

if ($action AND $confirm != "true") { ?>
	<blockquote>
	<form action="<?=$current_url;?>" method="post">
	&nbsp;&nbsp;&bull; <?=$T['really '.$action];?><b><?=$data['service'];?></b><br>
	&nbsp;&nbsp;&nbsp;<input type="submit" value="<?=$T['yes'];?>">
	<input type="hidden" name="action" value="<?=$action;?>">
	<input type="hidden" name="data[service]" value="<?=$data['service'];?>">
	<input type="hidden" name="confirm" value="true">
	</form>
	</blockquote>
<? } ?>
<table border="0" cellspacing="0" cellpadding="0" class="tblbg">
	<tr>
		<td>
		<table border="0" cellspacing="1">
			<tr>
				<td colspan="3" class="tbltop">&nbsp;<?=$T['menu'][$url];?>&nbsp;</td>
			</tr>
			<tr>
			<?
			foreach($monit as $key => $val) {
				if ($T[$key.' service'] != "") {
					?>
					<tr>
					<td nowrap class="row1">
					&nbsp;<B><?=$T[$key.' service'];?></B>&nbsp;
					</td>
					<td nowrap class="row2">
					<span class="service<?php
					if ($T[$val] == $T['up']) {
						echo 'ok">&nbsp;<img src="icon/up.gif" border="0" width="16" height="16" alt="'.$T['up'].'"/>&nbsp;'.$T['up'];
					} else {
						echo 'notok">&nbsp;<img src="icon/down.gif" border="0" width="16" height="16" alt="'.$T['down'].'"/>&nbsp;'.$T['down'];
					}
					?>&nbsp;</span>
					</td>
					<td class="row1">&nbsp;
					<?
						if ($T[$monit[$key]] == $T['up']) { ?>
							<a href="<?=$current_url;?>&data[service]=<?=$key;?>&action=stop"><img src="icon/stop.gif" border="0" width="32" height="32" alt="<?=$T['stop'];?>"></a>
						<? } else { ?>
							<a href="<?=$current_url;?>&data[service]=<?=$key;?>&action=start"><img src="icon/start.gif" border="0" width="32" height="32" alt="<?=$T['start'];?>"></a>
						<? } ?>
					<a href="<?=$current_url;?>&data[service]=<?=$key;?>&action=restart"><img src="icon/reboot.gif" border="0" width="32" height="32" alt="<?=$T['restart'];?>"></a>
					&nbsp;</td>
					</tr>
			<? 	}
			} ?>

			<tr>
				<td class="row1"><b>&nbsp;<?=$T['web-cp Backend'];?>&nbsp;</b></td>
				<td class="row2" height="32">
				<span class="service<?php
					if ($T[$monit['webcpbackend']] == $T['up']) {
						echo 'ok">&nbsp;<img src="icon/up.gif" border="0" width="16" height="16" alt="'.$T['up'].'"/>&nbsp;'.$T['up'];
					} else {
						echo 'notok">&nbsp;<img src="icon/down.gif" border="0" width="16" height="16" alt="'.$T['down'].'"/>&nbsp;'.$T['down'];
					}
					?>&nbsp;</span>
				</td>
				<td class="row1"></td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;<?=$T['Memory Usage'];?>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=($ram['total'] != 0) ? round($ram['used'] / $ram['total'] * 100) : 0;?>% RAM, <?=($swap['total'] != 0) ? round($swap['used'] / $swap['total'] * 100) : 0;?>% Swap&nbsp;</td>
				<td rowspan="3" class="row1"><div align="center">&nbsp;
					<a href="<?=$current_url;?>&data[service]=system&action=reboot"><img src="icon/reboot.gif" border="0" width="32" height="32" alt="<?=$T['restart'];?>"></a>
				&nbsp;</div></td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;<?=$T['Processor Usage'];?>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=$cpu['cpu'];?>&nbsp;</td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;<?=$T['Uptime'];?>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=$cpu['uptime'];?>&nbsp;</td>
			</tr>
			<?
			$dom = fetchdata("domains","total",0);
			$sub = fetchdata("subdomains","total",0);
			$ptr = fetchdata("pointers","total",0);
			$usr = fetchdata("users","total",0);
			$db  = fetchdata("db","total",0);
			?>
			<tr>
				<td class="row1"><b>&nbsp;Number of Domains&nbsp;</b></td>
				<td class="row2" colspan="2">&nbsp;<?=$dom['domains'];?>&nbsp;</td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;Number of Sub-Domains&nbsp;</b></td>
				<td class="row2" colspan="2">&nbsp;<?=$sub['subdomains'];?>&nbsp;</td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;Number of Domain Pointers&nbsp;</b></td>
				<td class="row2" colspan="2">&nbsp;<?=$ptr['pointers'];?>&nbsp;</td>
			</tr>
			<tr>
                <td class="row1"><b>&nbsp;<?=$T['Num Databases'];?>&nbsp;</b></td>
                <td class="row2" colspan="2">&nbsp;<?=$db['db'];?>&nbsp;</td>
            </tr>
			<tr>
				<td class="row1"><b>&nbsp;Number of Users&nbsp;</b></td>
				<td class="row2" colspan="2">&nbsp;<?=$usr['users'];?>&nbsp;</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</div>
<?
}

function monitor_serverinfo(&$data) {
	global $T;
	$cp = $data['_cp'];
	$url = $data['_url'];
	$action = $data['_action'];
	$confirm = $data['_confirm'];
	$userdata = $data['_userdata'];
	$personaldata = $data['_personaldata'];
	$domaindata = $data['_domaindata'];
	$resellerdata = $data['_resellerdata'];
	$cp = $data['_cp'];
	$url = $data['_url'];
	$action = $data['_action'];
	$confirm = $data['_confirm'];
	$current_url = $data['_current_url'];
	// Get system data
	$monit = get_stat('monitor');
	$ram = get_stat('ram');
	$swap = get_stat('swap');
	$cpu = get_stat('cpu');
	$uptime = get_stat('uptime');
	
	
	?>
	<div align=center>
<table border="0" cellspacing="0" cellpadding="0" class="tblbg">
	<tr>
		<td>
		<table border="0" cellspacing="1">
			<tr>
				<td colspan="3" class="tbltop">&nbsp;<?=$T['menu'][$url];?>&nbsp;</td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;<?=$T['Kernel'];?></a>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=php_uname("s")." ".php_uname("r")." (<I>".php_uname("m")."</I>)";?>&nbsp;</td>
			</tr>
						<?
			// get CPU info
			if ($fd = file('/proc/cpuinfo')) {
		      foreach($fd as $buf) {
        		list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);
				switch ($key) {
    		      case 'model name':
		            $model = $value;
        		    break;
		          case 'cpu MHz':
        		    $mhz = sprintf('%.2f', $value);
	        	    break;
    		      case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
		            $mhz = sprintf('%.2f', $value / 1000000);
        		    break;
		          case 'clock': // For PPC arch
        		    $mhz = sprintf('%.2f', $value);
		            break;
        		  case 'cpu': // For PPC arch
		            $model = $value;
        		    break;
        		}
        	}
        	}
			?>
			<tr>
				<td class="row1"><b>&nbsp;<?=$T['Processor'];?></a>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=str_replace("(tm)", "", $model)." (<I>".$mhz."Mhz</I>)";?>&nbsp;</td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;<a href='<?=$current_url;?>&url=serverstatus'><?=$T['menu']['serverstatus'];?></a>&nbsp;</b></td>
				<td class="row2">&nbsp;
					<?
						foreach($monit as $key => $val) {
							if ($T[$monit[$key]] == $T['up']) {
								$up += 1;
							}
							$total += 1;
						}
						echo "<span class='service".(($up < $total) ? "notok" : "ok")."'>";
						if ($up == $total) {
							echo "<img src=\"icon/up.gif\" border=\"0\" width=\"16\" height=\"16\" alt=\"".$T['up']."\" align=absmiddle>";
						} else {
							echo "<img src=\"icon/down.gif\" border=\"0\" width=\"16\" height=\"16\" alt=\"".$T['down']."\" align=absmiddle>";
						}
						echo "&nbsp;($up / $total ".$T['services up'].")</span>";
					?>

					&nbsp;</td>
			<tr>
				<td class="row1"><b>&nbsp;<a href='<?=$current_url;?>&url=serverstatus'><?=$T['web-cp Backend'];?></a>&nbsp;</b></td>
				<td class="row2">&nbsp;
					<?
						if ($T[$monit['webcpbackend']] == $T['up'])
							echo "<img src=\"icon/up.gif\" border=\"0\" width=\"16\" height=\"16\" alt=\"".$T['up']."\">";
						else
							echo "<img src=\"icon/down.gif\" border=\"0\" width=\"16\" height=\"16\" alt=\"".$T['down']."\">";
					?>
				&nbsp;</td>
			</tr>
			<tr>
				<td class="row1"><b>&nbsp;<?=$T['Uptime'];?>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=$cpu['uptime'];?>&nbsp;</td>
			</tr>
			<?
			call_hook('web:server:serverinfodetails', $hookdata);
			call_hook('web:server:serverresourcedetails', $hookdata);
}

function monitor_serverinfodetails(&$data) {
	global $T, $cfg;
	$cp = $data['_cp'];
	$url = $data['_url'];
	$action = $data['_action'];
	$confirm = $data['_confirm'];
	$userdata = $data['_userdata'];
	$personaldata = $data['_personaldata'];
	$domaindata = $data['_domaindata'];
	$resellerdata = $data['_resellerdata'];
	$cp = $data['_cp'];
	$url = $data['_url'];
	$action = $data['_action'];
	$confirm = $data['_confirm'];
	$current_url = $data['_current_url'];
	// Get system data
	$monit = get_stat('monitor');
	$ram = get_stat('ram');
	$swap = get_stat('swap');
	$cpu = get_stat('cpu');
	$uptime = get_stat('uptime');
	$ramlevel = 0.95;
	$swaplevel = 0.5;
	$cpulevel[0] = 1.0;
	$cpulevel[1] = 0.75;
	$cpulevel[2] = 0.5;
	$mountspacelevel = 85;
	?>
	<tr>
				<td class="row1" colspan=2><b>&nbsp;<?=$T['Memory Usage'];?></a>&nbsp;</b></td>
			</tr>
			<tr>
				<td colspan=2 class="content">
				<table cellpadding=0 cellspacing=1 width="100%">
				<tr class="features">
					<td><B><?=$T['Memory Type'];?></B></td>
					<td><B><?=$T['Used'];?></B></td>
					<td><B><?=$T['Total'];?></B></td>
					<td colspan="2"><B><?=$T['Used'];?> %</B></td>
				</tr>
				<tr>
					<td class="features">&nbsp;<?=$T['RAM'];?></td>
					<td class="features">&nbsp;<?=$ram['used'];?> MB</td>
					<td class="features">&nbsp;<?=$ram['total'];?> MB</td>
					<td class="features">&nbsp;<span class='service<?=(($ram['used'] > $ramlevel*$ram['total']) ? "notok" : "ok");?>'><?=($ram['total'] != 0) ? round($ram['used'] / $ram['total'] * 100) : 0;?>%</span></td>
					<td class="features"><div class="bargraphContainer"><div class='bargraph' style="width: <?=($ram['total'] != 0) ? round($ram['used'] / $ram['total'] * 100) : 0;?>%;"></div></div></td>

				</tr>
				<tr>
					<td class="features">&nbsp;<?=$T['SWAP'];?></td>
					<td class="features">&nbsp;<?=$swap['used'];?> MB</td>
					<td class="features">&nbsp;<?=$swap['total'];?> MB</td>
					<td class="features">&nbsp;<span class='service<?=(($swap['used'] > $swaplevel*$swap['total']) ? "notok" : "ok");?>'><?=($swap['total'] != 0) ? round($swap['used'] / $swap['total'] * 100) : 0;?>%</span></td>
					<td class="features"><div class="bargraphContainer"><div class='bargraph' style="width: <?=($swap['total'] != 0) ? round($swap['used'] / $swap['total'] * 100) : 0;?>%;"></div></div></td>

				</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td class="row1" colspan=2><b>&nbsp;<?=$T['Load Average'];?></a>&nbsp;</b></td>
			</tr>
			<tr>
				<td colspan=2 class="content">
				<table cellpadding=0 cellspacing=1 width="100%">
				<tr class="features">
					<td><B><?=$T['Processor'];?></B></td>
					<td><B><?=$T['1-Min'];?></B></td>
					<td><B><?=$T['5-Min'];?></B></td>
					<td><B><?=$T['15-Min'];?></B></td>
				</tr>
				<tr>
					<td class="features">&nbsp;<?=$T['CPU'];?></td>
				<?
					$cpu_array = explode(" : ", $cpu['cpu']);
					$i=0;
					foreach($cpu_array as $val) {
						echo "<td class='features'>&nbsp;<span class='service".(($val > $cpulevel[$i++]) ? "notok" : "ok")."'>".$val."</span> &nbsp;</td>";
					}
				?>
				</tr>
				</table>
				</td>
			</tr>
			<?
			$results = array();
			$m = 1024;
			if ($fp = file('/proc/net/dev')) {
				foreach($fp as $buf) {
				if (preg_match('/:/', $buf)) {
					list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
					$stats = preg_split('/\s+/', trim($stats_list));
					$results[$dev_name] = array();

					$results[$dev_name]['rx_bytes'] = $stats[0];
					$results[$dev_name]['rx_packets'] = $stats[1];
					$results[$dev_name]['rx_errs'] = $stats[2];
					$results[$dev_name]['rx_drop'] = $stats[3];

					$results[$dev_name]['tx_bytes'] = $stats[8];
					$results[$dev_name]['tx_packets'] = $stats[9];
					$results[$dev_name]['tx_errs'] = $stats[10];
					$results[$dev_name]['tx_drop'] = $stats[11];

					$results[$dev_name]['errs'] = $stats[2] + $stats[10];
					$results[$dev_name]['drop'] = $stats[3] + $stats[11];
				}
				}
    		?>
    		<tr>
				<td class="row1" colspan=2><b>&nbsp;<?=$T['Network Interfaces'];?></a>&nbsp;</b></td>
			</tr>
			<tr>
				<td colspan=2 class="content"><table cellpadding=0 cellspacing=1 width="100%">
				<tr class="features">
					<td><B><?=$T['Device'];?></B></td>
					<td><B><?=$T['Received'];?></B></td>
					<td><B><?=$T['Sent'];?></B></td>
					<td><B><?=$T['Errors'];?></B></td>
					<td><B><?=$T['Drops'];?></B></td>
				</tr>
				<?
				foreach($results as $key => $val) {
					$rx = file_size_info($val['rx_bytes'] * $m);
					$tx = file_size_info($val['tx_bytes'] * $m);

				?>
				<tr>
					<td class="features">&nbsp;<?=$key;?>:&nbsp;</td>
					<td class="features">&nbsp;<?=$rx['size'].$rx['type'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$tx['size'].$tx['type'];?>&nbsp;</td>
					<td class="features">&nbsp;<?="<span class='service".(($val['errs'] > 0) ? "notok" : "ok")."'>".$val['errs']."</span>";?>&nbsp;</td>
					<td class="features">&nbsp;<?="<span class='service".(($val['drop'] > 0) ? "notok" : "ok")."'>".$val['drop']."</span>";?>&nbsp;</td>
				</tr>
    			<? } ?>
    			</table>
	    		</td>
    		</tr>
    		<? }
			
			//if ($cfg['prog']['df'] != '' && !$cfg['httpd_prefork']) {
				exec($cfg['prog']['df'].' -kP',$mounts);
				$fstype = array();
				unset($results);
				if ($fd = file('/proc/mounts')) {
				foreach($fd as $buf) {
							list($dev, $mpoint, $type) = preg_split('/\s+/', trim($buf), 4);
							$fstype[$mpoint] = $type;
							$fsdev[$dev] = $type;
				}
				}
			$m = 1024 * 1024;
			for ($i = 1, $max = sizeof($mounts); $i < $max; $i++) {
			  $ar_buf = preg_split('/\s+/', $mounts[$i], 6);

			  $results[$i - 1] = array();
			  
			  $results[$i - 1]['disk'] = $ar_buf[0];
			  $results[$i - 1]['size'] = file_size_info($ar_buf[1]*$m);
			  $results[$i - 1]['used'] = file_size_info($ar_buf[2]*$m);
			  $results[$i - 1]['percent'] = round(($ar_buf[2]/$ar_buf[1])*100);
			  $results[$i - 1]['free'] = file_size_info($ar_buf[3]*$m);
			  $results[$i - 1]['mount'] = $ar_buf[5];
			  ($fstype[$ar_buf[5]]) ? $results[$i - 1]['fstype'] = $fstype[$ar_buf[5]] : $results[$i - 1]['fstype'] = $fsdev[$ar_buf[0]];
			}
    		?>
			<tr>
				<td class="row1" colspan=2><b>&nbsp;<?=$T['Mounts'];?></a>&nbsp;</b></td>
			</tr>
			<tr>
				<td colspan=2 class="content"><table cellpadding=0 cellspacing=1 width="100%">
				<tr class="features">
					<td><B><?=$T['Mount Point'];?></B></td>
					<td><B><?=$T['Size'];?></B></td>
					<td><B><?=$T['Available'];?></B></td>
					<td><B><?=$T['Used'];?></B></td>
					<td colspan="2"><B><?=$T['Used'];?> %</B></td>
				</tr>
				<?
				foreach($results as $val) {
					if (!isset($cfg['tuxdir']) || (isset($cfg['tuxdir']) && !(strpos($val['mount'], $cfg['tuxdir']) === 0))) {
				?>
				<tr>
					<td class="features">&nbsp;<?=$val['mount'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$val['size']['size'].$val['size']['type'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$val['free']['size'].$val['free']['type'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$val['used']['size'].$val['used']['type'];?>&nbsp;</td>
					<td class="features">&nbsp;<?="<span class='service".(($val['percent'] > $mountspacelevel) ? "notok" : "ok")."'>".$val['percent']." %</span>";?>&nbsp;</td>
					<td class="features"><div class="bargraphContainer"><div class='bargraph' style="width: <?=$val['percent'];?>%;"></div></div></td>
				</tr>
    			<?
					}
				} ?>
    			</table>
	    		</td>
    		</tr>
	<?
			//}
			return;
}

function monitor_resource_usage(&$data) {
	global $T;
			$dom = fetchdata("domains","total",0);
			$sub = fetchdata("subdomains","total",0);
			$ptr = fetchdata("pointers","total",0);
			$usr = fetchdata("users","total",0);
			$db  = fetchdata("db","total",0);
			$rs  = fetchdata("resellers","total",0);
			$domalloc = fetchdata("domains","alloc",0);
			$suballoc = fetchdata("subdomains","alloc",0);
			$ptralloc = fetchdata("pointers","alloc",0);
			$usralloc = fetchdata("users","alloc",0);
			$dballoc  = fetchdata("db","alloc",0);
			$rsalloc  = fetchdata("resellers","alloc",0);
			?>
			<tr>
				<td class="row1" colspan=2><b>&nbsp;<?=$T['Resource Usage'];?></a>&nbsp;</b></td>
			</tr>
			<tr>
				<td colspan=2 class="content">
				<table cellpadding=0 cellspacing=1 width="100%">
				<tr class="features">
					<td><B><?=$T['Resource'];?></B></td>
					<td><B><?=$T['Real'];?></B></td>
					<td><B><?=$T['Allocated'];?></B></td>
				</tr>
				<tr>
				<tr>
					<td class="features"><b>&nbsp;<?=$T['Number of Resellers'];?>&nbsp;</b></td>
					<td class="features">&nbsp;<?=$rs['resellers'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$rsalloc['resellers'];?>&nbsp;</td>
				</tr>
				<tr>
					<td class="features"><b>&nbsp;<?=$T['Number of Domains'];?>&nbsp;</b></td>
					<td class="features">&nbsp;<?=$dom['domains'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$domalloc['domains'];?>&nbsp;</td>
				</tr>
				<tr>
					<td class="features"><b>&nbsp;<?=$T['Number of Users'];?>&nbsp;</b></td>
					<td class="features">&nbsp;<?=$usr['users'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$usralloc['users'];?>&nbsp;</td>
				</tr>
				<tr>
					<td class="features"><b>&nbsp;<?=$T['Number of Sub-Domains'];?>&nbsp;</b></td>
					<td class="features">&nbsp;<?=$sub['subdomains'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$suballoc['subdomains'];?>&nbsp;</td>
				</tr>
				<tr>
					<td class="features"><b>&nbsp;<?=$T['Number of Domain Pointers'];?>&nbsp;</b></td>
					<td class="features">&nbsp;<?=$ptr['pointers'];?>&nbsp;</td>
					<td class="features">&nbsp;<?=$ptralloc['pointers'];?>&nbsp;</td>
				</tr>
				<tr>
					<td class="features"><b>&nbsp;<?=$T['Num Databases'];?>&nbsp;</b></td>
				    <td class="features">&nbsp;<?=$db['db'];?>&nbsp;</td>
				    <td class="features">&nbsp;<?=$dballoc['db'];?>&nbsp;</td>
				</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</div>
<?
}
?>
